include CouchControlBuild.mak

DIRS = src

MAKE0 = rm -f make.log
MAKEB = make -f ../config/makefile -j8 1>> ../make.log
MAKEC = make -f ../config/makefile clean 1>> ../make.log
MAKED = make -f ../config/makefile depends.mk 1>> ../make.log

BUILD = for dir in $(DIRS); do \
           echo Building $$dir; \
           cd $$dir; $(MAKEB) TARGET=lib$$dir; cd ..; \
        done; \

BUILDOPT = for dir in $(DIRS); do \
              echo Building $$dir; \
              cd $$dir; $(MAKEB) TARGET=lib$$dir OPTIMIZE=1; cd ..; \
           done;

CLEAN = for dir in $(DIRS); do \
           echo Cleaning $$dir; \
           cd $$dir; $(MAKEC); cd ..; \
        done;

DEPENDS = for dir in $(DIRS); do \
			    echo Updating dependencies in $$dir; \
				 cd $$dir; $(MAKED); cd ..; \
			 done

.PHONY: depend clean

all:
	$(MAKE0)
	@echo "============================================="
	@echo "Building the source tree"
	@echo "============================================="
	$(BUILD)
	cd bin; make TARGET=$(TARGET) 1>> ../make.log; cd ..
	@echo "Done"

release:
	$(MAKE0)
	@echo "============================================="
	@echo "Building the source tree"
	@echo "============================================="
	$(BUILDOPT)
	cd bin; make TARGET=$(TARGET) OPTIMIZE=1 1>> ../make.log; cd ..
	@echo "Done"

doc:
	cd docs; make; cd ..

clean:
	@echo "============================================="
	@echo "Cleaning the source tree"
	@echo "============================================="
	$(CLEAN) >> make.log
	cd bin; make clean 1>> ../make.log; cd ..
	cd bin; make cleanLib 1>> ../make.log; cd ..
	cd docs; make clean 1>> ../make.log; cd ..
	rm -f make.log core*
	@echo "Done"

depend:
	@echo "============================================="
	@echo "Building dependecy files in the source tree"
	@echo "============================================="
	$(DEPENDS)
	cd bin; make depend 1>> ../make.log; cd ..
	@echo "Done"
